﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;


namespace PRE.Thongke
{
    public partial class FrmTuyentheonam : DevExpress.XtraEditors.XtraForm
    {
        #region Variable
        DAL.EntitiesDAL.NhanvienDAL _dal = new DAL.EntitiesDAL.NhanvienDAL();
        BLL.EntitiesBLL.NhanvienBLL _bll = new BLL.EntitiesBLL.NhanvienBLL();

        DataTable _dt = new DataTable();
        DataTable _dt1 = new DataTable();
        #endregion

        #region Inits
        public FrmTuyentheonam()
        {
            InitializeComponent();
        }
        #endregion

        #region PerformRefresh
        private void PerformRefresh()
        {
            LoadData();
        }
        #endregion

        #region load
        private void LoadData()
        {
            _dt = _dal.Select_Thongke();
            _dt1 = _dal.Select_Nam();

            cbo_Nam.Properties.DataSource = _dt1;

            try
            {
                if (_dt != null)
                {
                    gridControl_Theonam.DataSource = _dt;

                    AppGridView.SummaryField(gridView_Theonam, "MANHANVIEN", "Tổng = {0:#,0} mẫu tin", DevExpress.Data.SummaryItemType.Count);

                    gridView_Theonam.OptionsBehavior.ReadOnly = true;
                    gridView_Theonam.OptionsView.ColumnAutoWidth = true;
                }


            }
            catch (Exception ex)
            {

                XtraMessageBox.Show("Lỗi! Không load được dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
        #endregion

        #region FrmTuyentheonam_Load
        private void FrmTuyentheonam_Load(object sender, EventArgs e)
        {
            PerformRefresh();
            bto_Loc.Visible = true;
            bto_In.Visible = true;
            bto_Thoat.Visible = true;
        }
        #endregion

        #region Lọc
        private void bto_Loc_Click(object sender, EventArgs e)
        {
            try
            {
                string Chonnam = Convert.ToString(cbo_Nam.EditValue);
                DataTable _dtSearch = _dal.Select_Thongke_Theonam(Chonnam);
                if (_dtSearch != null)
                {


                    gridControl_Theonam.DataSource = _dtSearch;

                    AppGridView.SummaryField(gridView_Theonam, "MANHANVIEN", "Tổng = {0:#,0} mẫu tin", DevExpress.Data.SummaryItemType.Count);

                    gridView_Theonam.OptionsView.EnableAppearanceEvenRow = true;
                    gridView_Theonam.OptionsView.ColumnAutoWidth = true;
                }
                gridControl_Theonam.DataSource = _dtSearch;

                _dt = _dtSearch;
            }
            catch (Exception ex)
            {

                XtraMessageBox.Show("Lỗi! Không lọc được dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion

        #region Làm tươi
        private void bto_Lamtuoi_Click(object sender, EventArgs e)
        {
            FrmTuyentheonam_Load(null, null);
        }
        #endregion

        #region Thoát
        private void bto_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region In
        private void bto_In_Click(object sender, EventArgs e)
        {
            string _NgayKy = "TP.Cần Thơ, ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year;
            if (gridView_Theonam.DataRowCount > 0)
            {
                DataTable dt = gridView_Theonam.GetDataRow(0).Table.Clone();

                for (int i = 0; i < gridView_Theonam.DataRowCount; i++)
                {
                    dt.ImportRow(gridView_Theonam.GetDataRow(i));
                }
                Reports.FrmReportView frm = new Reports.FrmReportView();
                frm._load_XtraTuyentheonam(dt, _NgayKy);
                frm.Show();
            }
        }
        #endregion
    }
}
